package com.dly.hope.modle;

import com.dly.hope.type.DataStatusEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author linyu.dai
 * @project myserve
 * @description
 * @creat 2022/8/26 10:35:57
 */
@EntityListeners(value = AuditingEntityListener.class)
@Data
@Accessors(chain = true)
@MappedSuperclass
@JsonIgnoreProperties(value = {"handler", "hibernateLazyInitializer"})
public class BaseEntity implements Serializable {

    @Column(name = "obj_status")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    @Comment(value = "状态")
    private Integer dataStatus = DataStatusEnum.EFFICIENT.getCode();

    @Column(name = "obj_createdate")
    @Comment(value = "创建时间")
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy.MM.dd HH:mm:ss", timezone = "GMT+08:00")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private Date createDate = new Date();

    @CreatedBy
    @Column(name = "obj_createuser")
    @Comment(value = "创建人")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private String createUser;

    @Column(name = "obj_modifydate")
    @Comment(value = "更新时间")
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy.MM.dd HH:mm:ss", timezone = "GMT+08:00")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private Date modifyDate = new Date();

    @LastModifiedBy
    @Column(name = "obj_modifyuser")
    @Comment(value = "更新人")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private String modifyUser;
}
